package com.sanhuo.idms.service;

import com.sanhuo.idms.dao.ElectricScheduleDayMapper;
import com.sanhuo.idms.entity.ElectricScheduleDay;
import com.sanhuo.triild.Basic.BaseMapper;
import com.sanhuo.triild.Basic.BaseService;
import com.sanhuo.triild.annotation.MapperWire;
import com.sanhuo.utils.basic.Dateutil;
import com.sanhuo.utils.basic.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Transactional
@Service
public class ElectricScheduleDayService extends BaseService<ElectricScheduleDay> {
    @MapperWire
    private ElectricScheduleDayMapper electricScheduleDayMapper;

    @Override
    public BaseMapper<ElectricScheduleDay> getBaseMapper() {
        return electricScheduleDayMapper;
    }

    public void save(String dormId, double consume) throws ParseException {
        ElectricScheduleDay electricSchedule = new ElectricScheduleDay();
        electricSchedule.setId(StringUtil.UUID());
        electricSchedule.setDormId(dormId);
        electricSchedule.setConsume(consume);
        electricSchedule.setCreateTime(Dateutil.getNowDate(Dateutil.dateTime));
        save(electricSchedule);
    }

    public List<Double> todayConsume(String dormId) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String today = sdf.format(new Date()) + "%";
        return electricScheduleDayMapper.findTodayByDorm(dormId, today);
    }
}
